
import 'babel-polyfill'
import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from "./router"
import store from "./store"
import moment from 'moment/moment' //moment.js
// import * as echarts from 'echarts' //5.x版本
import  VueClipboard from 'vue-clipboard2'
import http from 'axios'


// 导入封装工具
import {request} from './http/apiRequest'
import {stringutils} from './utils/stringutils'
import {toast} from './utils/toast'
Vue.prototype.toast = toast
Vue.prototype.request = request //http请求
Vue.prototype.stringutils = stringutils //工具集
Vue.prototype.moment = moment 
// Vue.prototype.$echarts = echarts
Vue.prototype.$http = http
Vue.use(ElementUI)
Vue.use(VueClipboard)


/*
  ---过滤器filter---
*/
//日期
Vue.filter('YMD', function (value, formatString) {
	if (!value) {
		return '请选择'
	}
	formatString = formatString || 'YYYYMMDD'
	return moment(value).format(formatString)
})
Vue.filter('moment', function (value, formatString) {
	if (!value) {
		return '-'
	}
	formatString = formatString || 'YYYY-MM-DD'
	return moment(value).format(formatString)
})
Vue.filter('moment_ss', function (value, formatString) {
	if (!value) {
		return '-'
	}
	formatString = formatString || 'YYYY-MM-DD HH:mm:ss'
	return moment(value).format(formatString)
})
//价格
Vue.filter('price', function (value) {
	if (!value||Number(value<0)) {
		return '0.00'
	}
	value = Number(value).toFixed(2); //保留两位小数 四舍五入
	return value;
})
//数量
Vue.filter('num', function (value) {
	if (!value||Number(value<0)) {
		return '0'
	}
	return value;
})
//字段
Vue.filter('text', function (value) {
	if (!value) {
		return '-'
	}
	return value;
})
Vue.config.productionTip = false
//路由拦截
router.beforeEach((to, from, next) => {
	/* 路由发生变化修改页面title */
	if (to.meta.title) {
		document.title = `${to.meta.title}`;
	}
	// if (to.matched.some(res => res.meta.requireAuth)) {
	// 	let token = store.getters.token;
	// 	if (token != '' && token != null && token != undefined) {
	// 		next();
	// 	}else{
	// 		next({
	// 			// path: '/login',// 未登录则跳转至login页面
	// 		})
	// 	}
    // } 
	next();
	
});
//Vue路由跳转新页面无法回到顶部
router.afterEach(() => {
    document.documentElement.scrollTop = 0;
});
new Vue({
	router,
	store,
	render: h => h(App),
}).$mount('#app')